package com.itheima.tlias84.service.impl;


import com.itheima.tlias84.dto.SelectAllDeptDTO;
import com.itheima.tlias84.entity.Dept;
import com.itheima.tlias84.mapper.DeptMapper;
import com.itheima.tlias84.po.InsertDeptParam;
import com.itheima.tlias84.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.Local;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service
public class DeptServiceImpl implements DeptService{
    @Autowired
    DeptMapper deptMapper;

    @Override
    public SelectAllDeptDTO selectDeptById(Integer id) {
        return deptMapper.selectDeptById(id);
    }

    @Override
    public int updateDeptById(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
       return deptMapper.updateDeptById(dept);
    }

    @Override
    public List<SelectAllDeptDTO> selectAll() {
        List<SelectAllDeptDTO> selectAllDeptDTOS = deptMapper.selectAll();
        return selectAllDeptDTOS;
    }

    @Override
    public int insertDept(InsertDeptParam param) {
        Dept dept = new Dept();
        dept.setName(param.getName());
        dept.setUpdateTime(LocalDateTime.now());
        dept.setCreateTime(LocalDateTime.now());
        int flag = deptMapper.insertDept(dept);
        return flag;
    }

    @Override
    public int deleteById(Integer id) {
        int a = 1;
        if (a==1){
            throw new ArithmeticException();
        }
        int delete = deptMapper.deleteById(id);
        return delete;
    }
    //校验部门名称是否重复

    //根据id以及name 查询部门

}
